//
//  doTaskViewController.m
//  PCR
//
//  Created by shumei_imac on 2016/7/19.
//  Copyright © 2016年 shumei. All rights reserved.
//

#import "doTaskViewController.h"
#import"doTaskSecondDayViewController.h"
#import "AppDelegate.h"
@interface doTaskViewController ()
@property (weak, nonatomic) IBOutlet UIButton *submitBtn;
- (IBAction)submitBtnClick:(id)sender;

@end

@implementation doTaskViewController
NSTimer *countDownTimer;
int secondsCountDown; 
- (void)viewDidLoad {
    [super viewDidLoad];
    self.tabBarController.tabBar.hidden = YES;
    
    AppDelegate * app = [UIApplication sharedApplication].delegate;
    [app.tabBar setTabbarHidden];
    
    __block int time = 5;
    _submitBtn.enabled = NO;
    dispatch_queue_t queue = dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0);
    dispatch_source_t _timer = dispatch_source_create(DISPATCH_SOURCE_TYPE_TIMER, 0, 0,queue);
    dispatch_source_set_timer(_timer,dispatch_walltime(NULL, 0),1.0*NSEC_PER_SEC, 0);
    dispatch_source_set_event_handler(_timer, ^{
        if(time<=1){
            dispatch_source_cancel(_timer);
            dispatch_async(dispatch_get_main_queue(), ^{
                _submitBtn.enabled = YES;
                _submitBtn.backgroundColor = [UIColor redColor];
                _submitBtn.titleLabel.text = @"下一步";
                [_submitBtn setTitle:@"下一步" forState:UIControlStateNormal];
            });
        }else{
            dispatch_async(dispatch_get_main_queue(), ^{
               
//                _submitBtn.backgroundColor = [UIColor redColor];
                NSString *strTime = [NSString stringWithFormat:@"下一步(%d秒后可操作)",time];
                _submitBtn.titleLabel.text = strTime;
            });
            time--;
        }
    });
    dispatch_resume(_timer);
    
   
    
    //设置倒计时总时长
    secondsCountDown = 60;//60秒倒计时
    //开始倒计时
//    countDownTimer = [NSTimer scheduledTimerWithTimeInterval:1 target:self selector:@selector(timeFireMethod) userInfo:nil repeats:YES]; //启动倒计时后会每秒钟调用一次方法 timeFireMethod
    // Do any additional setup after loading the view from its nib.
}



//-(void)timeFireMethod{
//    //倒计时-1
//    secondsCountDown--;
//    //修改倒计时标签现实内容
//    _submitBtn.titleLabel.text=[NSString stringWithFormat:@"%d",secondsCountDown];
//    //当倒计时到0时，做需要的操作，比如验证码过期不能提交
//}

-(void)viewWillDisappear:(BOOL)animated{
    AppDelegate * app = [UIApplication sharedApplication].delegate;
    [app.tabBar setTabbarShow];
}

- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

/*
#pragma mark - Navigation

// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
    // Get the new view controller using [segue destinationViewController].
    // Pass the selected object to the new view controller.
}
*/

- (IBAction)submitBtnClick:(id)sender {
    doTaskSecondDayViewController *Vc = [doTaskSecondDayViewController new];
    [self.navigationController pushViewController:Vc animated:YES];
}
@end
